﻿
CREATE FUNCTION [dbo].[FormatFix]
(@Num varchar(50),@Digits int)
RETURNS varchar(50) AS  
BEGIN 

DECLARE @S as char

SET @S = CASE WHEN @Num LIKE '%[^0-9]%' THEN ' ' ELSE '0' END

RETURN ISNULL(REPLICATE(@S,@Digits-LEN(@Num)),'')+@Num

END

